bool isPalindrome(struct ListNode* head) {
    struct ListNode* cur = head;

    // 先算出链表的长度
    int len = 0;
    while (cur) {
        len++;
        cur = cur->next;
    }

    // 创建数组
    int* temp = (int*)malloc(len * sizeof(int));
    if (NULL == temp) {
        perror("malloc fail");
        exit(-1);
    }

    // 将链表的值复制到数组
    cur = head;
    int i = 0;
    while (cur) {
        temp[i] = cur->val;
        cur = cur->next;
        i++;
    }

    // 使用双指针判断
    int left = 0;
    int right = len - 1;
    while (left < right) {
        if (temp[left] != temp[right]) {
            free(temp);
            temp = NULL;
            return false;
        }
        left++;
        right--;
    }
    free(temp);
    temp = NULL;
    return true;
}
